import java.util.ArrayList;
import java.util.Scanner;

/*
 *@author wangpeng
 *2023/7/16 20:32
 *@description TODO
 */

public class Test {
    public static void main(String[] args) {
        //使用集合
        ArrayList list = new ArrayList();

        while (true) {
            System.out.println("--------《欢迎来到Java书籍管理》--------");
            System.out.println("1.展示书籍");
            System.out.println("2.上新书籍");
            System.out.println("3.下架书籍");
            System.out.println("4.退出应用");
            //借助Scanner类
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入你想要执行的功能序号：");
            int choice = sc.nextInt();

            if (choice == 1) {
                System.out.println("【Java书籍管理】>>>>>>>>>1.展示书籍");
                for (int i = 0; i <= list.size() - 1; i++) {
                    Book b = (Book) (list.get(i));
                    System.out.println(b.getbNum() + "---" + b.getbName() + "---" + b.getbAuthor());
                }
            }else if (choice == 2) {
                System.out.println("【Java书籍管理】>>>>>>>>>2.上新书籍");
                System.out.println("请录入书籍的编号：");
                int bNum = sc.nextInt();
                System.out.println("请录入书籍的名字：");
                String bName = sc.next();
                System.out.println("请录入书籍的作者：");
                String bAuthor = sc.next();
                Book b = new Book();  //每上新一本书，，就要创建一个对象
                b.setbNum(bNum);
                b.setbName(bName);
                b.setbAuthor(bAuthor);

                list.add(b);
            }else if (choice == 3) {
                System.out.println("【Java书籍管理】>>>>>>>>>3.下架书籍");
                System.out.println("请录入需要下架的书籍的编号：");
                int deleteNum = sc.nextInt();
                for(int i =0;i <= list.size()-1;i++){
                    Book b =(Book) (list.get(i));
                    if(b.getbNum() == deleteNum){
                        list.remove(b);
                        System.out.println("书籍下架成功！");
                        break;
                    }
                }
            }else if (choice == 4) {
                System.out.println("【Java书籍管理】>>>>>>>>>4.退出应用");
                break;
            }else{
                System.out.println("你的输入选项功能有误，请从新输入！");
            }
        }
    }
}
